<template>
	<view class="login">
		<view class="main">
			<view class="topbox">
				<image src="http://img.cpgm.cc/panda/static/login/logoimg.png" mode="widthFix" />
				<text>挑战模式+自由副本+创新小程序</text>
			</view>

			<view class="in">
				<view class="piece">
					<text>账号:</text>
					<input type="number" maxlength="11" v-model="phone" placeholder="请输入手机号"
						placeholder-style="color:#A1A1A1;" />
				</view>
				<view class="piece">
					<text>密码:</text>
					<input type="password" v-model="password" placeholder="请输入密码"
						placeholder-style="color:#A1A1A1;" />
				</view>
				<view class="reg">
					<text @click="forget">忘记密码?</text>
					<text @click="register">没有账号，去注册</text>
				</view>
				<view class="login_bottom">
					<view class="button btn " @click="login">
						登 录
					</view>
				</view>
			</view>

			<u-checkbox-group class="checkgroup">
				<u-checkbox v-model="checked" shape="" :label-disabled="false" size="28"
					active-color="#4938AE" class="checkbox">
					<view class="explain">
						<span>登录即表示同意</span>
						<text class="yellow" @click="xieyi">《用户协议》</text>
						<span>和</span>
						<text class="yellow" @click="yinsi">《隐私政策》</text>
					</view>
				</u-checkbox>
			</u-checkbox-group>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				checked: false,
				phone: '',
				password: '',
			};
		},
		methods: {
			xieyi() {
				uni.navigateTo({
					url: './agreement'
				});
			},
			yinsi() {
				uni.navigateTo({
					url: './privacy'
				});
			},
			register() {
				uni.navigateTo({
					url: './register'
				});
			},
			forget() {
				uni.navigateTo({
					url: './forget'
				});
			},

			// 登录
			async login() {
				//  if (!/^1[3456789]\d{9}$/.test(this.phone)) {
				// 	this.$u.toast("手机号有误");
				// } else 
				if (this.phone == '' || this.phone == null) {
					this.$u.toast("请输入手机号")
				} else if (this.password == '' || this.password == null) {
					this.$u.toast("请输入密码")
				} else if (!this.checked) {
					this.$u.toast("请勾选并同意用户协议与隐私政策")
				} else {

					let res = await this.$http.index.login({
						account: this.phone,
						pwd: this.password
					})
					if (res.code == 1) {
						uni.setStorageSync('token', res.token)
						uni.setStorageSync('id', res.data.id)
						this.$u.toast(res.msg)
						setTimeout(function() {
							uni.switchTab({
								url: '/pages/tabbar/home'
							});
						}, 1500);
					} else {
						this.$u.toast(res.msg)
					}
				}
			},
		},
	}
</script>

<style lang="less">

.login {
	background: url('http://img.cpgm.cc/panda/static/login/bg.jpg');
	background-size: 100% 100%;
	min-height: 100vh;
}

.main {
	padding: 10vh 15px 15px;
}

.topbox {
	display: flex;
	flex-direction: column;
	align-items: center;

	image {
		width: 40%;
		border-radius: 10px;
	}

	text {
		font-size: 18px;
		font-weight: 800;
		color: #FFFFFF;
		line-height: 24px;
		letter-spacing: 1px;
		background: linear-gradient(90deg, #77FFFF 0%, #248EF6 100%);
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		margin-top: 20px;
	}
}



.in {
		margin-top: 35px;
	}

	.piece {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20px 15px;
		margin: 10px 0;
		background: rgba(242,242,242,0.95);
		border-radius: 7px;
	}

	.piece text {
		width: 20%;
		font-size: 14px;
		font-weight: 600;
	}

	.piece image {
		width: 20px;
		height: 20px;
	}

	.piece input {
		width: 80%;
		font-size: 14px;
		color: #131314;
	}

	.reg {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 5px;
		font-size: 12px;
	}

	.reg text {
		color: #fff;
		font-weight: 600;
	}

	.checkgroup {
		width: 100%;
		display: flex;
		align-items: center;
		text-align: center;
		justify-content: center;
		margin-top: 15px;
	}

	.checkbox {
		margin: 0 auto;

	}


	.btn {
		font-size: 14px;
		width: 90%;
		margin: 0 auto;
		margin-top: 4vh;
		height: 60px;
		line-height: 60px;
		text-align: center;
		color: #000;
		background: linear-gradient(90deg, #77FFFF 0%, #248EF6 100%);
		box-shadow: inset 0px 4px 0px 0px rgba(0,0,0,0.5);
		border-radius: 7px;
		font-weight: 600;
		font-size: 18px;
	}

	.explain {
		font-size: 12px;
		color: #343434;
		font-weight: 600;
	}

	.yellow {
		font-size: 12px;
		color: #fff;
		font-weight: 600;
	}

	/deep/ .u-checkbox__icon-wrap--checked {
		background:  linear-gradient(90deg, #77FFFF 0%, #248EF6 100%) !important; 
	}



</style>
